package com.ourway.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.ourway.dtos.DepartmentDTO;
import com.ourway.entity.Department;
import com.ourway.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 部门数据持久层
 *
 * @author liuweiheng
 * @since 2021/12/11
 */
@Mapper
public interface DepartmentMapper extends BaseMapper<Department>, MPJBaseMapper<Department> {

    /**
     * 根据部门ID查询
     * @param deptId 部门ID
     * @return 部门信息
     */
    @Select("select * from department where department_id = #{deptId}")
    Department findByDeptId(@Param("deptId") String deptId);

    /**
     * 获取部门列表
     * @param pageIndex 页数
     * @param pageSize 每页数量
     * @return 部门列表
     */
    @Select("select d1.*, d2.name as parentName from department d1 left join department d2 on d1.parent_id = d2.department_id")
    List<DepartmentDTO> findDeptListByPage(int pageIndex, int pageSize);
}
